# -*- coding: utf-8 -*-
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule


class ZhipinSpider(CrawlSpider):
    name = 'zhipin'
    allowed_domains = ['www.zhipin.com']
    start_urls = [
        'https://www.zhipin.com/c101270100/?query=python&page=1&ka=page-1'
    ]

    rules = (
        Rule(LinkExtractor(allow=r'.+?query=python&page=\d&ka=page-\d'), follow=True),
        Rule(LinkExtractor(allow=r'.+?query=python&page=\d&ka=page-\d'),
             callback='parse_detail', follow=False)
    )

    def parse_detail(self, response):
        item = {}
        #item['domain_id'] = response.xpath('//input[@id="sid"]/@value').get()
        #item['name'] = response.xpath('//div[@id="name"]').get()
        #item['description'] = response.xpath('//div[@id="description"]').get()
        return item
